package deephard.JZ22;

import java.util.*;
public class Solution {
    public class TreeNode {
        int val = 0;
        TreeNode left = null;
        TreeNode right = null;

        public TreeNode(int val) {
            this.val = val;

        }
    }
    public ArrayList<Integer> PrintFromTopToBottom(TreeNode root) {
        ArrayList<Integer> list=new ArrayList<>();
        if(root==null)
            return list;
        Queue<TreeNode> queue=new LinkedList<>();
        TreeNode node=root;
        while(node!=null){
            list.add(node.val);
            if(node.left!=null){
                queue.add(node.left);
            }
            if(node.right!=null){
                queue.add(node.right);
            }
            node=queue.poll();
        }
        return list;
    }
}
